export class GameUtils {
  // 生成随机房间号
  static generateRoomId() {
    return Math.floor(100000 + Math.random() * 900000).toString()
  }
  
  // 生成随机骰子点数
  static rollDice() {
    return Math.floor(Math.random() * 6) + 1
  }
  
  // 检查按钮点击
  static isButtonClicked(x, y, button) {
    return (
      x >= button.x &&
      x <= button.x + button.width &&
      y >= button.y &&
      y <= button.y + button.height
    )
  }
  
  // 绘制圆角矩形
  static drawRoundRect(ctx, x, y, width, height, radius) {
    ctx.beginPath()
    ctx.moveTo(x + radius, y)
    ctx.lineTo(x + width - radius, y)
    ctx.quadraticCurveTo(x + width, y, x + width, y + radius)
    ctx.lineTo(x + width, y + height - radius)
    ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height)
    ctx.lineTo(x + radius, y + height)
    ctx.quadraticCurveTo(x, y + height, x, y + height - radius)
    ctx.lineTo(x, y + radius)
    ctx.quadraticCurveTo(x, y, x + radius, y)
    ctx.closePath()
  }
  
  // 绘制文本
  static drawText(ctx, text, x, y, options = {}) {
    const {
      font = '24px Arial',
      color = '#000',
      align = 'left',
      baseline = 'top'
    } = options
    
    ctx.font = font
    ctx.fillStyle = color
    ctx.textAlign = align
    ctx.textBaseline = baseline
    ctx.fillText(text, x, y)
  }
  
  // 格式化时间
  static formatTime(seconds) {
    const minutes = Math.floor(seconds / 60)
    const remainingSeconds = seconds % 60
    return `${minutes}:${remainingSeconds.toString().padStart(2, '0')}`
  }
} 